<template>
	<div id="GroupFieldModel">
		{{workName}}
		<el-table :data="tableData" height="80vh" ref="topicTable" align="center" row-key="WorkID" default-expand-all 
			:row-class-name="tableRowClassName" >
			    <el-table-column
			            label="序号" width="50px">
			        <template slot-scope="scope">
			            {{scope.$index+1}}
			        </template>
			    </el-table-column>
			<el-table-column type="selection" >
				
			</el-table-column>
            <el-table-column prop="Title" label="标题"  min-width="350" max-width="400" >
			</el-table-column>

			<el-table-column prop="Starter" label="发起人" width="80">
			</el-table-column>

			<el-table-column prop="ADT" label="接收日期" width="150">
			</el-table-column> 
			  <template v-for="(item,index) in tableHead">
			    <el-table-column :prop="item.prop" :label="item.label" :key="index" ></el-table-column>
			  </template>

		</el-table>
		<el-button size="mini" type="warning"  @click="Send()">办理</el-button>
		<el-button size="mini" v-if="btns.ReturnRole!=0" type="warning"  @click="Btn_Return()">退回</el-button>
		<el-button size="mini" v-if="btns.DelEnable!=0" type="warning"  @click="Btn_Delete()">删除</el-button>
		<el-button size="mini" type="warning"  @click="Btn_Back()">返回</el-button>
		<div style="margin:10px 0;">
			<span style="font-weight: 500;font-size: 14px;margin-right:10px;color: #606266;">合计： {{count}}条</span>
		</div>
	</div>
</template>

<script>
	import { Entity } from "../../api/Gener.js";
	export default {
		name: "GroupFieldModel",
		components: {},

		data() {
			return {
				title: "批处理-审核分组",
				tableData: [],
				count: 0,
				activeNames: [],
				NodeID:"",
				workName:"",
				node:null,
				tableHead:[],
				btns:{"ReturnRole":0,"DelEnable":0},
				Sort:1
			};
		},

		beforeCreate() {},

		created() {
			this.loadData();
		},
		methods: {
			tableRowClassName({
				row
			}) {
				if (row.type === null)
					return '';
				if (row.type === 1) {
					return 'success-row';
				}
				return '';
			},
/* 			initData:function(){
			    this.FK_Flow = this.$route.params.FK_Flow;
			    var fromPage = this.$route.params.FromPage;
			    if(fromPage == "Start" || fromPage=="Todolist")
			        this.myFlowInit();
			    else
			       this.myFrmInit(); 
			}, */
			// 获取数据
			loadData() {
				this.NodeID = this.$route.params.NodeID;
				if(this.NodeID==null){
					return;
				}
				let handler = new this.HttpHandler("BP.WF.HttpHandler.WF_WorkOpt_Batch");
				//handler.AddUrlData();
				//var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt_Batch");
				handler.AddPara("FK_Node", this.NodeID);
				
				let data = handler.DoMethodReturnString("WorkCheckModel_Init");
				//var data = handler.DoMethodReturnString("WorkCheckModel_Init");
				if (data.indexOf("err@") != -1) {
					this.$message.error(data);
					console.log(data);
					return;
				}
				data = JSON.parse(data);
				this.filterData(data);
			},

			// 过滤数据
			filterData(data) {
				var works = data.Works; //数据.
				var mapAttrs = data.Sys_MapAttr; //要显示的字段.
				this.node = new Entity("BP.WF.Node", this.NodeID);
				
				var BatchCheckNoteModel = this.node.GetPara("BatchCheckNoteModel");
				if (BatchCheckNoteModel == undefined)
				    BatchCheckNoteModel = "0"; //审核意见填写方式,默认为选择的Item一个意见.
				this.workName = "流程：" +this. node.FlowName + " => 节点：" + this.node.Name;
				
				// 是否动态添加字段
				var files = this.node.GetPara("BatchFields");debugger;
				for (var i = 0; i < mapAttrs.length; i++) {
				    var attr = mapAttrs[i];
				    if (files == undefined)
				        continue;
				    if (files.indexOf(attr.KeyOfEn) == -1)
				        continue;
				    if (attr.Name == "审核意见")
				        continue;
					var file={
						label:attr.Name,
						prop:attr.KeyOfEn
					};
					this.tableHead.push(file);
				    //thead += "<th>" + attr.Name + "</th>";
				}
				
				//判断该节点是否启用审核组件
				var sta = this.node.FWCSta;
				////启用审核组件并且可编辑 ，如果是：每个记录后面都有一个意见框.的模式.
				if (sta == 1 && BatchCheckNoteModel == "1") {
				   // thead += "<th>审核意见</th>";
					var file={
						label:"审核意见",
						prop:"KeyOfEn"
					};
				}
				

				
				this.count = works.length;
				var flowNos = "";
				this.tableData = works;
				/* works.forEach(item => {
					if (flowNos.indexOf(item.FK_Flow + ",") == -1) {
						this.tableData.push({
							Title: item.FlowName,
							WorkID: parseInt(item.FK_Flow),
							type: 1, //流程
							children: this.GetChildren(item.FK_Flow, data)
						});
						flowNos += item.FK_Flow + ",";
					}
				}); */
				
				//处理按钮权限
				this.btns = data.Sys_BtnLab[0];
				
			},
			Btn_Return() {
				this.$confirm('您确定要执行本次批处理退回操作吗？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
				}).then(() => {
					var handler = new this.HttpHandler("BP.WF.HttpHandler.WF");
					handler.AddFormData();
					handler.AddPara("FK_Node", GetQueryString("FK_Node"));
					var data = handler.DoMethodReturnString("Batch_Return");
					if (data.indexOf("err@") != -1) {
						alert(data);
						return;
					}
					data = data.replace(/@/g, '<br/>@');
					//$("#msgContent").html(data);
					this.$message.error(data);
				});

			},
			Btn_Back(){
				this.$router.push({name:"batchbo"});
			},
			Btn_Delete() {

				this.$confirm('你确定要取消吗？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
				}).then(() => {
					var handler = new this.HttpHandler("BP.WF.HttpHandler.WF");
					handler.AddFormData();
					handler.AddPara("FK_Node", GetQueryString("FK_Node"));
					var data = handler.DoMethodReturnString("Batch_Delete");
					if (data.indexOf("err@") != -1) {
					    alert(data);
					    return;
					}
					data = data.replace(/@/g, '<br/>@');
					//$("#msgContent").html(data);
					this.$message.error(data);
				});

			    $("#batchModal").modal().show();
			    // $("#batchModal").find('.modal-title').text(label);
			    data = data.replace(/@/g, '<br/>@');
			    $("#msgContent").html(data);
			    $('#batchModal').on('hidden.bs.modal', function () {
			        window.location.href = window.location.href;
			
			    });
			    $("#batchModal").modal("hidden");
			},
			


			//跳转myflow
			sikpMyflow(work) {
				console.log(work);
				let params = {
					IsRead: work.IsRead,
					FK_Flow: work.FK_Flow,
					FK_Node: work.FK_Node,
					FID: work.FID,
					WorkID: work.WorkID,
					PWorkID: work.PWorkID,
					Paras: work.AtPara ? work.AtPara : '',
				}
				// eslint-disable-next-line no-constant-condition
				while (true) {
					params.Paras = params.Paras.replace('@', '&');

					if (params.Paras.indexOf('@') < 0) {
						break;
					}
				}
				params.Paras = "1" + params.Paras;
				console.log(params);
				params.FromPage = 'Todolist';
				// this.$router.push("myFlow?FK_Flow=350");
				this.$router.push({
					name: "myflow",
					params
				});
			},

		},

		//监听
		computed: {},

		//监听后执行动作
		watch: {}
	};
</script>
<style>
	.el-table .success-row {
		background: #f5f7fa;
		padding: 5px 0px;
	} 
	.el-table td, .el-table th{
			padding: 8px 0px !important;
	}
</style>
<style lang="less" scoped>
	
	
	.ml-5 {
		padding-left: 5px;
	}
    .mr-20{
		padding-right: 20px;
	}
	.iconColor {
		color: #F56C6C;
	}

	.iconColor-w {
		color: #909399;
	}

	.cellfontColor {
		color: #545454;
		font-weight: 600;
	}
</style>
